//
//  ByDocumentaryApi.m
//  caipiao_ios
//
//  Created by mc on 2018/8/16.
//  Copyright © 2018年 ZhangZhanbin. All rights reserved.
//

#import "ByDocumentaryApi.h"

@implementation ByDocumentaryApi


//发起跟单
+ (void)followOrderAddPlan:(ByNetModel *)model
                   success:(void(^)(ByNetBaseResult *result))success
                   failure:(void(^)(ByNetBaseResult *result))failure{
    
    // 拼接参数
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    if (model.lottery_type) {
      [params setObject:model.lottery_type forKey:@"lottery_type"];
    }else{
      [params setObject:@"1" forKey:@"lottery_type"];
    }
    
    [params setObject:@"0" forKey:@"type"];
    if (model.numArray) {
        [params setObject:[self toJSONData:model.numArray] forKey:@"num"];
    }
    
    if (model.multiple) {
        [params setObject:model.multiple forKey:@"multiple"];
    }
    
    
    if (model.free_pass) {
        [params setObject:model.free_pass forKey:@"free_pass"];
    }
    
    if (model.public_type) {
        [params setObject:model.public_type forKey:@"public_type"];
    }else{
        [params setObject:@"2" forKey:@"public_type"];
    }
    
    if (model.reason) {
        [params setObject:model.reason forKey:@"reason"];
    }
    
    if (model.low_amount) {
        [params setObject:model.low_amount forKey:@"low_amount"];
    }
    
    if (model.ensure_odds) {
        [params setObject:model.ensure_odds forKey:@"ensure_odds"];
    }
    
    if (model.origin_numDic) {
        [params setObject:[self toJSONData:model.origin_numDic] forKey:@"origin_num"];
    }
    

    SLog(@"params =%@", params);
    
    [self post:@"/followOrder/addPlan" params:params success:^(id result) {
        
        ByNetBaseResult *result1 = [[ByNetBaseResult alloc] init];
        result1.code = 0;
        result1.msg = @"获取成功";
        result1.data = result;
        if(success) {
            success(result1);
        }
    } failure:^(NSError *error) {
        
        ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
        result.code = error.code;
        result.msg = error.domain;
        result.data = error.localizedDescription;
        if(failure) {
            failure(result);
        } else {
            
        }
        
    }];
    
    
}

+ (NSString *)toJSONData:(id)theData{
    
    NSError *error = nil;
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:theData
                                                       options:NSJSONWritingPrettyPrinted
                                                         error:&error];
    
    if ([jsonData length] > 0 && error == nil){
        return [[NSString alloc] initWithData:jsonData
                                     encoding:NSUTF8StringEncoding];;
    }else{
        return @"";
    }
}



//跟单首页接口
+ (void)followOrderIndex:(ByNetModel *)model
                 success:(void(^)(ByNetBaseResult *result))success
                 failure:(void(^)(ByNetBaseResult *result))failure{
    NSString *str = @"";
    if (model.is_follow.integerValue == 1) {
        str =  [NSString stringWithFormat:@"/FollowOrder/followIndex?sort=%ld&&page=1&&page_size=100&&is_follow=%@", model.type,model.is_follow];
    }else{
        str =  [NSString stringWithFormat:@"/FollowOrder/followIndex?sort=%ld&&page=1&&page_size=100", model.type];
    }
    [self get:str params:nil success:^(id result) {
        
        ByNetBaseResult *result1 = [[ByNetBaseResult alloc] init];
        result1.code = 0;
        result1.msg = @"获取成功";
        result1.data = result;
        if(success) {
            success(result1);
        }
        
      } failure:^(NSError *error) {
          ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
          result.code = error.code;
          result.msg = error.domain;
          result.data = error.localizedDescription;
          if(failure) {
              failure(result);
          } else {
              
          }
      }];
    
    
}


//红人榜
+ (void)followOrderRedList:(ByNetModel *)model
                   success:(void(^)(ByNetBaseResult *result))success
                   failure:(void(^)(ByNetBaseResult *result))failure{
    [self get:@"/FollowOrder/redList?" params:nil success:^(id result) {
        
        ByNetBaseResult *result1 = [[ByNetBaseResult alloc] init];
        result1.code = 0;
        result1.msg = @"获取成功";
        result1.data = result;
        if(success) {
            success(result1);
        }
        
    } failure:^(NSError *error) {
        ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
        result.code = error.code;
        result.msg = error.domain;
        result.data = error.localizedDescription;
        if(failure) {
            failure(result);
        } else {
            
        }
    }];
    
    
    
}

//用户跟单
+ (void)followOrderFollowPlan:(ByNetModel *)model
                      success:(void(^)(ByNetBaseResult *result))success
                      failure:(void(^)(ByNetBaseResult *result))failure{
    
    
    // 拼接参数
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
   
    
    if (model.plan_id) {
        [params setObject:model.plan_id forKey:@"plan_id"];
    }
    
    if (model.num) {
        [params setObject:model.num forKey:@"num"];
    }else{
        [params setObject:@"1" forKey:@"num"];
    }
    [self post:@"/followOrder/followPlan" params:params success:^(id result) {
        
        ByNetBaseResult *result1 = [[ByNetBaseResult alloc] init];
        result1.code = 0;
        result1.msg = @"获取成功";
        result1.data = result;
        if(success) {
            success(result1);
        }
    } failure:^(NSError *error) {
        
        ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
        result.code = error.code;
        result.msg = error.domain;
        result.data = error.localizedDescription;
        if(failure) {
            failure(result);
        } else {
            
        }
        
    }];
}


//大神跟单详情
+ (void)followOrderGodOrderDetail:(ByNetModel *)model
                          success:(void(^)(ByNetBaseResult *result))success
                          failure:(void(^)(ByNetBaseResult *result))failure{
    
    
    [self get:[NSString stringWithFormat:@"/FollowOrder/godOrderDetail?orderId=%@", model.ID] params:nil success:^(id result) {
        
        ByNetBaseResult *result1 = [[ByNetBaseResult alloc] init];
        result1.code = 0;
        result1.msg = @"获取成功";
        result1.data = result;
        if(success) {
            success(result1);
        }
        
    } failure:^(NSError *error) {
        ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
        result.code = error.code;
        result.msg = error.domain;
        result.data = error.localizedDescription;
        if(failure) {
            failure(result);
        } else {
            
        }
    }];
    
}

//大神首页
+ (void)followOrderGodIndex:(ByNetModel *)model
                    success:(void(^)(ByNetBaseResult *result))success
                    failure:(void(^)(ByNetBaseResult *result))failure{
    
    [self get:[NSString stringWithFormat:@"/FollowOrder/godIndex?uid=%@&&type=%ld", model.uid,model.type] params:nil success:^(id result) {
               
               ByNetBaseResult *result1 = [[ByNetBaseResult alloc] init];
               result1.code = 0;
               result1.msg = @"获取成功";
               result1.data = result;
               if(success) {
                   success(result1);
               }
               
               } failure:^(NSError *error) {
                   ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
                   result.code = error.code;
                   result.msg = error.domain;
                   result.data = error.localizedDescription;
                   if(failure) {
                       failure(result);
                   } else {
                       
                   }
    }];
}

+ (void)followOrderMyPlanList:(ByNetModel *)model
                      success:(void(^)(ByNetBaseResult *result))success
                      failure:(void(^)(ByNetBaseResult *result))failure{
    
    
    // 拼接参数
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    
    
    if (model.type) {
        [params setObject:[NSString stringWithFormat:@"%ld",model.type] forKey:@"type"];
    }else{
        [params setObject:@"1" forKey:@"type"];
    }
    
    if (model.page) {
        [params setObject:model.page forKey:@"page"];
    }else{
        [params setObject:@"1" forKey:@"page"];
    }
    
    if (model.page_size) {
        [params setObject:model.page_size forKey:@"page_size"];
    }else{
        [params setObject:@"100" forKey:@"page_size"];
    }
    [self post:@"/FollowOrder/myPlanList" params:params success:^(id result) {
        
        ByNetBaseResult *result1 = [[ByNetBaseResult alloc] init];
        result1.code = 0;
        result1.msg = @"获取成功";
        result1.data = result;
        if(success) {
            success(result1);
        }
    } failure:^(NSError *error) {
        
        ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
        result.code = error.code;
        result.msg = error.domain;
        result.data = error.localizedDescription;
        if(failure) {
            failure(result);
        } else {
            
        }
        
    }];
}

+ (void)followOrderFollowPlanList:(ByNetModel *)model
                          success:(void(^)(ByNetBaseResult *result))success
                          failure:(void(^)(ByNetBaseResult *result))failure{
    
    // 拼接参数
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    
    
    if (model.type) {
        [params setObject:[NSString stringWithFormat:@"%ld",model.type] forKey:@"type"];
    }else{
        [params setObject:@"1" forKey:@"type"];
    }
    
    if (model.page) {
        [params setObject:model.page forKey:@"page"];
    }else{
        [params setObject:@"1" forKey:@"page"];
    }
    
    if (model.page_size) {
        [params setObject:model.page_size forKey:@"page_size"];
    }else{
        [params setObject:@"100" forKey:@"page_size"];
    }
    
    
    [self post:@"/FollowOrder/followPlanList" params:params success:^(id result) {
        
        ByNetBaseResult *result1 = [[ByNetBaseResult alloc] init];
        result1.code = 0;
        result1.msg = @"获取成功";
        result1.data = result;
        if(success) {
            success(result1);
        }
    } failure:^(NSError *error) {
        
        ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
        result.code = error.code;
        result.msg = error.domain;
        result.data = error.localizedDescription;
        if(failure) {
            failure(result);
        } else {
            
        }
        
    }];
    
}


//跟单详情
+ (void)followOrderMyPlanDetail:(ByNetModel *)model
                        success:(void(^)(ByNetBaseResult *result))success
                        failure:(void(^)(ByNetBaseResult *result))failure{
    
    
    // 拼接参数
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    if (model.ID) {
        [params setObject:model.ID forKey:@"orderId"];
    }
    [self post:@"/FollowOrder/myPlanDetail" params:params success:^(id result) {
        
        ByNetBaseResult *result1 = [[ByNetBaseResult alloc] init];
        result1.code = 0;
        result1.msg = @"获取成功";
        result1.data = result;
        if(success) {
            success(result1);
        }
    } failure:^(NSError *error) {
        
        ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
        result.code = error.code;
        result.msg = error.domain;
        result.data = error.localizedDescription;
        if(failure) {
            failure(result);
        } else {
            
        }
        
    }];
    
}

+ (void)followOrderFollowPlanDetail:(ByNetModel *)model
                            success:(void(^)(ByNetBaseResult *result))success
                            failure:(void(^)(ByNetBaseResult *result))failure{
    
    // 拼接参数
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    if (model.ID) {
        [params setObject:model.ID forKey:@"orderId"];
    }
    
    if (model.lu_id) {
        [params setObject:model.lu_id forKey:@"lu_id"];
    }
    [self post:@"/FollowOrder/followPlanDetail" params:params success:^(id result) {
        
        ByNetBaseResult *result1 = [[ByNetBaseResult alloc] init];
        result1.code = 0;
        result1.msg = @"获取成功";
        result1.data = result;
        if(success) {
            success(result1);
        }
    } failure:^(NSError *error) {
        
        ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
        result.code = error.code;
        result.msg = error.domain;
        result.data = error.localizedDescription;
        if(failure) {
            failure(result);
        } else {
            
        }
        
    }];
    
}

//关注列表和粉丝列表
+ (void)followOrderFollowList:(ByNetModel *)model
                      success:(void(^)(ByNetBaseResult *result))success
                      failure:(void(^)(ByNetBaseResult *result))failure{
    
    
    // 拼接参数
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
//    if (model.follow) {
//        [params setObject:model.follow forKey:@"follow"];
//    }
    
    [self post:@"/FollowOrder/followList" params:params success:^(id result) {
        
        ByNetBaseResult *result1 = [[ByNetBaseResult alloc] init];
        result1.code = 0;
        result1.msg = @"获取成功";
        result1.data = result;
        if(success) {
            success(result1);
        }
    } failure:^(NSError *error) {
        
        ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
        result.code = error.code;
        result.msg = error.domain;
        result.data = error.localizedDescription;
        if(failure) {
            failure(result);
        } else {
            
        }
        
    }];
    
}

//关注大神
+ (void)followOrderFollow:(ByNetModel *)model
                  success:(void(^)(ByNetBaseResult *result))success
                  failure:(void(^)(ByNetBaseResult *result))failure{
    
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
   
    [params setObject:model.status forKey:@"status"];
    [params setObject:model.uid forKey:@"uid"];
    [self post:@"/FollowOrder/follow" params:params success:^(id result) {
        
        ByNetBaseResult *result1 = [[ByNetBaseResult alloc] init];
        result1.code = 0;
        result1.msg = @"获取成功";
        result1.data = result;
        if(success) {
            success(result1);
        }
    } failure:^(NSError *error) {
        
        ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
        result.code = error.code;
        result.msg = error.domain;
        result.data = error.localizedDescription;
        if(failure) {
            failure(result);
        } else {
            
        }
        
    }];
    
}


@end
